/**
 * huize Service Inc
 * All Rights Reserved @2018
 */
package com.huize.zhike.framework.common.enumeration;

import com.huize.ladon.apm.common.enums.EnumInterface;
import org.apache.commons.lang3.StringUtils;

import java.util.stream.Stream;

/**
 * 描述:
 *
 * @author tianyuliang
 * @version $Id: SortTypeEnum.java, v0.1 2021/3/15
 */
public enum SortTypeEnum implements EnumInterface {

    /**
     * 升序
     */
    ASC("asc", "升序"),

    /**
     * 降序
     */
    DESC("desc", "降序"),

    ;

    private String type;

    private String desc;

    SortTypeEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static SortTypeEnum of(String code) {
        if (StringUtils.isEmpty(code)) {
            return ASC;
        }

        return Stream.of(values()).filter(b -> b.getCode().equalsIgnoreCase(code.trim())).findFirst().orElseGet(() -> ASC);
    }


    public String getType() {
        return type;
    }

    @Override
    public String getCode() {
        return type;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return String.format("[%s,%s]", getCode(), getDesc());
    }

}